package com.thoughtful.loadbalance;

import java.util.List;

import com.thoughtful.remoting.dto.RpcRequest;
import com.thougtful.utils.CollectionUtil;

/**
 * @author yushun
 * @createTime 2022/10/19 - 17:00
 **/
public abstract class AbstractLoadBalance implements LoadBalance {

    @Override
    public String selectServiceAddress(List<String> serviceAddress, RpcRequest rpcRequest) {
        if (CollectionUtil.isEmpty(serviceAddress)) {
            return null;
        }
        if (serviceAddress.size() == 1) {
            return serviceAddress.get(0);
        }
        return doSelect(serviceAddress, rpcRequest);
    }

    protected abstract String doSelect(List<String> serviceAddress, RpcRequest rpcRequest);
}
